package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    NursingLevelMapper nursingLevelMapper;
    @Override
    public List<NursingLevelVo> getAll() {
        return nursingLevelMapper.getAll();
    }

    @Override
    public void addLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel=new NursingLevel();
        BeanUtils.copyProperties(nursingLevelDto,nursingLevel);
         nursingLevelMapper.addLevel(nursingLevel);
    }

    @Override
    public NursingLevelVo getById(Integer id) {
        return nursingLevelMapper.getById(id);
    }

    @Override
    public PageResponse<NursingLevelVo> queryPage(Integer pageNum, Integer pageSize, String name, Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        Page pageNursingLevel= nursingLevelMapper.pagequery(name,status);
        return PageResponse.of(pageNursingLevel, NursingLevelVo.class);
    }

    @Override
    public void updateLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel=new NursingLevel();
        BeanUtils.copyProperties(nursingLevelDto,nursingLevel);
        nursingLevelMapper.updateLevel(nursingLevel);
    }

    @Override
    public void deleteNursingLevel(Integer id) {
        nursingLevelMapper.deleteById(id);
    }

    @Override
    public void setStatus(Integer id, Integer status) {
        nursingLevelMapper.setStatus(id,status);
    }
}
